package com.shop.web;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.shop.entity.Emp;
import com.shop.service.EmpService;

@Controller
@RequestMapping("/emp")
public class EmpController {
	@Autowired
	private EmpService empService;
	
	@ResponseBody
	@RequestMapping("/deleteEmp")
	public List<Emp> deleteEmp(String id){
		//id获取传入的参数 18,19,20
		String ids[] = id.split(",");//数组
		List<Integer> list =new ArrayList<Integer>();
		for (String s : ids) {
			//把数组的元素添加到list
			list.add(Integer.parseInt(s));
		}
		int result = empService.deleteEmps(list);
		if(result > 0){
			System.out.println("删除成功");
		}
		return empService.findAll();
	}
	
	
	@RequestMapping("/findAll")
	public String findAll(Map<String,Object> map){
		List<Emp> list = empService.findAll();
		map.put("list", list);
		return "list";
	}
	public EmpService getEmpService() {
		return empService;
	}
	public void setEmpService(EmpService empService) {
		this.empService = empService;
	}
	
}
